#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <GL/glut.h>

using namespace std;

#define VERBOSE_MODE 0
#define TIMER_ON 1
#define WINDOWS_ENVIRONMENT 1

// Structured used to implement linkedList.
struct coordList
{
	int x, y, z;
	coordList *nextPtr;
};

#include "displayClass.h"
displayClass dispObj;

#include "apple.h"
Apple appleObj;

#include "snake.h"
Snake snakeObj;

#include "word.h"
Word wordObj;

float _xAngle = 0.0f;
float _yAngle = 0.0f;

#if WINDOWS_ENVIRONMENT == 1
	#include "simulator.h"
#endif



/****************************************************
 *
 *	Edit this function for Keypresses.
 *		If a key is pressed, the respective case will be executed.
 *
 ****************************************************/
void handleKeypress( unsigned char key, int x, int y ) {
	switch ( key ) {
		case 27: //Escape key
			exit(0);
			break;
		case 'a':
		case 'A': // Camera Left
			_yAngle += 15.0f;
			glutPostRedisplay(); //Tell GLUT that the display has changed
			break;
		case 'd':
		case 'D': // Camera Right
			_yAngle -= 15.0f;
			glutPostRedisplay(); //Tell GLUT that the display has changed
			break; 
		case 'w':
		case 'W': // Camera Up
			_xAngle += 15.0f;
			glutPostRedisplay(); //Tell GLUT that the display has changed
			break;		
		case 's':
		case 'S': // Camera Down
			_xAngle -= 15.0f;
			glutPostRedisplay(); //Tell GLUT that the display has changed
			break;
		case 'u':
		case 'U': //Down key
			snakeObj.changeDirection( 'U' );	
			dispObj.addElementToScreen( snakeObj.giveSnake(), snakeObj.firstPrevState, snakeObj.lastPrevState );
			glutPostRedisplay();
			break;
		case 'o':
		case 'O': //Down key
			snakeObj.changeDirection( 'D' );
			dispObj.addElementToScreen( snakeObj.giveSnake(), snakeObj.firstPrevState, snakeObj.lastPrevState );
			glutPostRedisplay();
			break;
		case 'k':
		case 'K': //Down key
			snakeObj.changeDirection( 'F' );
			dispObj.addElementToScreen( snakeObj.giveSnake(), snakeObj.firstPrevState, snakeObj.lastPrevState );
			glutPostRedisplay();
			break;
		case 'i':
		case 'I': //Down key
			snakeObj.changeDirection( 'B' );
			dispObj.addElementToScreen( snakeObj.giveSnake(), snakeObj.firstPrevState, snakeObj.lastPrevState );
			glutPostRedisplay();
			break;
		case 'l':
		case 'L': //Down key
			snakeObj.changeDirection( 'R' );
			dispObj.addElementToScreen( snakeObj.giveSnake(), snakeObj.firstPrevState, snakeObj.lastPrevState );
			glutPostRedisplay();
			break;
		case 'j':
		case 'J': //Down key
			snakeObj.changeDirection( 'L' );
			dispObj.addElementToScreen( snakeObj.giveSnake(), snakeObj.firstPrevState, snakeObj.lastPrevState );
			glutPostRedisplay();
			break;
		default:
			break;
	}
}

int main( int argc, char** argv ) {
	// Seeding Random generator
	srand( time(0) );
	
	// Adding apple object to the display screen 
	dispObj.addElementToScreen( appleObj.giveApple(), appleObj.firstPrevState, appleObj.secondPrevState );

	initializeGLUT( argc, argv );




	return 0;
}









